<%@page import="com.df.springmvc.system.manage.controller.InitController"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>系统初始化</title>
<jsp:include page="/scripts/common/index.html"></jsp:include>
<jsp:include page="/scripts/jquery/index.html"></jsp:include>
<jsp:include page="/scripts/bootstrap/index.html"></jsp:include>
<jsp:include page="/scripts/dhtmlx/index.html"></jsp:include>
<link rel="stylesheet" href="${basePath }style/default.css">
</head>
<script type="text/javascript">
	$(function() {
		initToolbar();
		query();
	});
	function query() {
		var url = '${basePath}page/system/manage/Init/queryFileTree';
		var data = {};
		$.ajax({
				type : 'POST' ,
				url : url ,
				data : data ,
				dataType : "json" ,
				async : true ,
				cache : false ,
				jsonpCallback : "jsonpCallback" ,
				success : function(response, status, statusText) {
					//alert(response + ":" + status + ":" + statusText);
					var content = response.content;
					if (response.status) {
						getTree().parse(content, "jsarray");
					} else {
						alert(content);
					}
				}
		});
	}
	function onSelect(id, name, pid) {
		if (pid != "0") {
			showSql(pid, id.replace(pid + "#", ""));
		}
	}
	function initToolbar() {
		//重置
		$("#repeat").click(function() {
			window.location.reload();
		});
	}
	function deal() {
		if ("" == $("#model").val()) {
			alert("请选择你要执行命令");
			return;
		}
		var url = '${basePath}page/system/manage/Init/doUpd';
		var data = {
				"map.model" : $("#model").val() ,
				"map.id" : $("#id").val()
		};
		$.ajax({
				type : 'POST' ,
				url : url ,
				data : data ,
				dataType : "json" ,
				async : true ,
				cache : false ,
				jsonpCallback : "jsonpCallback" ,
				success : function(response, status, statusText) {
					//alert(response + ":" + status + ":" + statusText);
					if (response.status) {
						// 						$("#model").val("");
						// 						$("#id").val("");
						$("#preview").text(response.content);
					} else {
						alert(response.content);
					}
				}
		});
	}
	function showSql(model, id) {
		$("#model").val(model);
		$("#id").val(id);
		var url = '${basePath}page/system/manage/Init/doView';
		var data = {
				"map.model" : model ,
				"map.id" : id
		};
		$.ajax({
				type : 'POST' ,
				url : url ,
				data : data ,
				dataType : "json" ,
				async : true ,
				cache : false ,
				jsonpCallback : "jsonpCallback" ,
				success : function(response, status, statusText) {
					//alert(response + ":" + status + ":" + statusText);
					if (response.status) {
						$("#preview").text(response.content);
					} else {
						alert(response.content);
					}
				}
		});
	}
</script>
<body>
	<form class="form-horizontal MyForm" id="MyForm" name="MyForm" method="post" target="MyFrame" enctype="multipart/form-data">
		<table class="listTableClass" border="1" cellpadding="0" cellspacing="0" style="width: 100%;height: 100%">
			<tr style="height: 30px;" class="queryClass">
				<td colspan="6">
					<button onclick="deal()" class="btn btn-primary" type="button">
						<span class="glyphicon glyphicon-play" aria-hidden="true"></span>
						&nbsp;
						<span>执行</span>
					</button>
					<button class="btn btn-primary" type="button" id="repeat">
						<span class="glyphicon glyphicon-repeat" aria-hidden="true"></span>
						&nbsp;
						<span>重置</span>
					</button>
				</td>
			</tr>
			<tr style="height: auto">
				<td style="width: 180px;">
					<jsp:include page="/common/tree.jsp">
						<jsp:param name="getTree" value="getTree" />
						<jsp:param name="isCheck" value="false" />
						<jsp:param name="onSelect" value="onSelect" />
					</jsp:include>
				</td>
				<td>
					<table style="width: 100%;height: 100%;" border="0" cellpadding="0" cellspacing="0">
						<tbody>
							<tr style="height: 30px;">
								<td style="width: auto;">
									脚本预览
									<input type="hidden" id="model" name="model" value="" style="">
									<input type="hidden" id="id" name="id" value="" style="">
								</td>
							</tr>
							<tr style="height: auto;">
								<td style="width: auto;">
									<textarea id="preview" style="width: 100%;height: 100%; wrap:no-wrap; overflow: scroll;" readonly="readonly"></textarea>
								</td>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
